<?php
/**
 * Created by PhpStorm.
 * User: zhan
 * Date: 2018/8/17  14:22
 */
namespace app\admin\controller;
use think\Db;

class Platform extends Common
{
    private $table_admin = "";
    /*
   *	构造函数
   */
    function __construct()
    {
        parent::__construct();
        $this->table_admin=db('order');
    }

    public function index()
    {
        $result = db('platform_amount')->order('id desc')->paginate(15);
        $this->assign('list', $result);
        $this->assign('page', $result->render());
        return $this->fetch();
    }

    public function detail()
    {
        $id = input('id/d');
        $platform = db('platform_amount')->where('id='.$id)->find();
        $this->assign('plat', $platform);
        if(!empty($platform['order_id'])){
            $data = db('order')->where('id='.$platform['order_id'])->find();
            $data['user'] = db('member')->where('id='.$data['user_id'])->value('nickname');
            $model = 'Platform/order';
        }
        if(!empty($platform['order_return_id'])){
            $data = db('order_return')->where('id='.$platform['order_return_id'])->find();
            $data['user'] = db('member')->where('id='.$data['buyer_user_id'])->value('nickname');
            $data['order_sn'] = db('order')->where('id='.$data['order_id'])->value('order_sn');
            if(!empty($data['certificate_image'])){
                $data['certificate_image'] = json_decode($data['certificate_image']);
                foreach ($data['certificate_image'] as $key => &$value) {
                    $value = IMG_PATH.$value; //给数据集追加字段num并赋值
                }
            }
            $model = 'Platform/orderreturn';
        }
        if(!empty($platform['wid'])){
            $data = db('withdraw')->where('id='.$platform['wid'])->find();
            $data['user'] = db('member')->where('id='.$data['user_id'])->value('nickname');
            $model = 'Platform/withdraw';
        }
        $this->assign('da',$data);
        return $this->fetch($model);
    }

}